package com.yaozheng.vocationaltraining.service.impl.integral;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.integral.IMyLocusView;
import com.yaozheng.vocationaltraining.service.integral.MyLocusSerivce;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

import java.util.HashMap;

/**
 * 我的轨迹
 */
@EBean
public class MyLocusSerivceImpl implements MyLocusSerivce {
    IMyLocusView iMyLocusView;

    @Override
    public void init(IMyLocusView iMyLocusView) {
        this.iMyLocusView = iMyLocusView;
    }

    @Background
    @Override
    public void trackData() {
        try {
            OkHttpClientManager.getInstance().get(
                    Constants.ROOTURL + "/user/track",
                    iMyLocusView.getToken(), new BaseView(iMyLocusView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iMyLocusView.trackDataSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iMyLocusView.trackDataError(error);
                        }
                    });
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iMyLocusView.isResponseResult()) {
                iMyLocusView
                        .trackDataError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }
}
